var sqls = [`CREATE TABLE if NOT EXISTS school (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name VCHAR(100) NOT NULL,
    number VCHAR(100) NOT NULL,
    userName VCHAR(100) NOT NULL,
    password VCHAR(100) NOT NULL,
    contact VCHAR(100),
    phone VCHAR(100)
 );`,
  `CREATE TABLE if NOT EXISTS people (
    id VCHAR(100) PRIMARY KEY ,
    vid INTEGER ,
    name VCHAR(100) ,
    number VCHAR(100),
    headImage TEXT,
    type INTEGER ,
    nation VCHAR(100),
    startDate VCHAR(100),
    endDate VCHAR(100),
    issue VCHAR(100),
    address VCHAR(100),
    sex VCHAR(100),
    shootphoto TEXT,
    birthday VCHAR(100),
    createdAt DATETIME DEFAULT(datetime('now','localtime'))
 );`,
  `CREATE TABLE if NOT EXISTS inout (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    uID  VCHAR(100) ,
    sex VCHAR(100),
    name VCHAR(100) ,
    fullImage TEXT,
    headImage TEXT,
    cardImage TEXT,
    time DATETIME,
    devName VCHAR(100),
    number VCHAR(100),
    inOut VCHAR(100),
    score VCHAR(100)
 );`,
  `CREATE TABLE if NOT EXISTS visitor (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    uID VCHAR(100) ,
    name VCHAR(100) ,
    vid INTEGER,
    number VCHAR(100),
    headImage TEXT,
    type INTEGER ,
    nation VCHAR(100),
    startDate VCHAR(100),
    endDate VCHAR(100),
    issue VCHAR(100),
    address VCHAR(100),
    sex VCHAR(100),
    shootphoto TEXT,
    birthday VCHAR(100),
    time DATETIME
 );`,
  `CREATE INDEX if NOT EXISTS uid_time
on visitor (uID, time)`]

module.exports = app => {
  app.beforeStart(async () => {
    sqls.forEach(async function (item) {
      const result = await app.db.run(item)
      console.log('初始化数据库', result)
    }, this);
  });
};